package com.sys.basics.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sys.basics.entity.vo.LogsVo;
import lombok.extern.slf4j.Slf4j;
import com.sys.basics.config.jsonRes.JsonResult;
import com.sys.basics.config.jsonRes.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.sys.basics.entity.SysLog;
import com.sys.basics.service.SysLogService;
import io.swagger.annotations.*;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.Map;

/**
 * @author: ares
 * @date: 2021-10-08
 * @description: 系统日志表 前端控制器
 */
@Validated
@Slf4j
@Api(tags = "系统日志管理")
@RestController
@RequestMapping("/basics/sysLog")
public class SysLogController extends AbstractController<SysLogService, SysLog> {

	@Autowired
	SysLogService sysLogService;


	@ApiOperation("清空日志")
	@DeleteMapping("/clear")
	public JsonResult clear() {
		int clearedNum = sysLogService.clear();
		if (clearedNum > 0) {
			return result.success("清空日志成功");
		}else {
			return result.error("清空日志失败");
		}
    }


	@ApiOperation("批量删除日志")
	@DeleteMapping("/batchRemove")
	public JsonResult batchRemove(@RequestBody List<Long> ids){
		int removedNum = sysLogService.batchRemove(ids);
		if (removedNum > 0) {
			return result.success("删除日志成功");
		}else {
			return result.error("删除日志失败");
		}
	}

	@ApiOperation("分页查询")
	@PostMapping("/getPageList")
	public JsonResult<IPage<LogsVo>> getPageList(@RequestBody PageParam<LogsVo> param) {
		JsonResult<IPage<LogsVo>> returnPage = new JsonResult<IPage<LogsVo>>();
		Page<LogsVo> page = new Page<LogsVo>(param.getPageNum(), param.getPageSize());
		IPage<LogsVo> pageData = sysLogService.getPageList(page, param.getParam());
		returnPage.success(pageData);
		return returnPage;
	}
 }
